package cn.bdqn.web.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;


public class CustomRealm extends AuthorizingRealm {
	
	@Override
	public String getName() {
		return "CustomRealm";
	}
	
	
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(
			AuthenticationToken token) throws AuthenticationException {
		
		System.out.println("开始认证.......");
		
		//获得用户名
		String username = (String) token.getPrincipal();
		//service
		if(!"admin".equals(username)){
			//用户名错误
			return null;
		}
		String password = "1234";
//		if(密码一致)
//		Session session = SecurityUtils.getSubject().getSession();
//		session.setAttribute("DevUser", );
		return new SimpleAuthenticationInfo(username, password, getName());
	}
	
	
	
	
	
	
	
	
	
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(
			PrincipalCollection principals) {
		// TODO Auto-generated method stub
		return null;
	}

	

}
